/*
 * FileName: SysUserService.java
 *
 *  
 */
package com.mrc.core.service;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.mrc.core.base.Constant;
import com.mrc.core.dao.SysUserDao;
import com.mrc.core.model.SysUser;

@Service
@Transactional
public class SysUserService {

    @Autowired
    private SysUserDao sysUserDao;

    /**
    * 根据请求，获得当前登录用户信息
    * @param request
    * @return
    */
    public SysUser getCurrentUser(HttpServletRequest request) {
        String mobile = (String) request.getSession().getAttribute(Constant.USER_SESSION_NAME);
        return this.findByMobile(mobile);
    }

    /**
     * 列出所有用户
     * @return
     */
    public List<SysUser> listAll() {
        return sysUserDao.list();
    }

    /**
     * 根据手机号码查询用户
     * @param userName
     */
    public SysUser findByMobile(String userMobile) {
        return sysUserDao.findByMobile(userMobile);
    }

}
